/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import mint.mvc.annotation.BaseMapping;
import mint.mvc.annotation.Mapping;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import pojo.Aboutus;
import pojo.CarPailiang;
import pojo.Faqcontent;
import pojo.Indexcontent;
import pojo.User;
import util.HibernateUtil;
import util.JSONRenderer;

@BaseMapping("/aboutus")
public class AboutusAtion {

    /**
     * "/index" 和 "/"都可以访问到此方法
     *
     * @return
     */
    @Mapping(urls = {"/get"}, method = "get")
    public JSONRenderer login() {
        Session ss = HibernateUtil.getSessionFactory().openSession();
        String hql = "from Aboutus where id = 1";
        Query query = ss.createQuery(hql);
        List<Aboutus> list = query.list();
        Aboutus iid = new Aboutus();
        if (list.size() > 0) {
            iid = list.get(0);
        }
        ss.close();
        return new JSONRenderer(iid);
    }

    @Mapping(urls = {"/set"}, method = "post")
    public String add_pailiang(String faq1, String faq2, String faq3, String faq4, String faq5, String faq6, String faq7) {
        Session ss = HibernateUtil.getSessionFactory().openSession();
        ss.beginTransaction();
        Aboutus iid = (Aboutus) ss.get(Aboutus.class, 1);
        iid.setP1(faq1);
        iid.setP2(faq2);
        iid.setP3(faq3);
        iid.setP4(faq4);
        iid.setP5(faq5);
        iid.setP6(faq6);
//        iid.setP7(faq7);
        ss.update(iid);
        ss.getTransaction().commit();
        ss.close();

        return "更新，<a href=../setaboutus.jsp>返回</a>";
    }
}
